package org.web;

import org.entity.User;
import org.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by dengry on 15/1/19.
 */
@Controller
public class SimpleController {
    Logger log = LoggerFactory.getLogger(SimpleController.class);

    @Autowired
    UserService userService;

    @RequestMapping(value = "/simple", method = RequestMethod.POST)
    public ModelAndView simple(@RequestParam String username, @RequestParam int password) {
        log.debug("username:" + username + "|password:" + password);
        User u = userService.getUserByUsernameAndPassword(username, password);

        if (u != null) {
            return new ModelAndView("simple");
        } else {
            return new ModelAndView("err");
        }

    }
}
